<!--
 * @Author: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @Date: 2023-08-28 14:39:14
 * @LastEditors: raoyonggang 11886335+ryg321@user.noreply.gitee.com
 * @LastEditTime: 2024-06-04 11:46:06
 * @FilePath: \v9\src\views\warehouse\warehouseDelivery.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="mainsu">
    <div class="main_spac1">
      <div class="main_white padding10">
        <div class="mainor_form">
          <el-form
            :inline="true"
            :model="form"
            class="demo-form-inline"
            ref="userListFrom"
            label-width="90px"
            id="form"
          >
            <el-form-item label="配送日期：" prop="send_time">
              <el-date-picker
                v-model="form.send_time"
                type="date"
                class="wid220"
                :editable="false"
                placeholder="选择配送日期"
                value-format="yyyy-MM-dd"
                :clearable="false"
                @change="getArticleList"
              />
            </el-form-item>
            <el-form-item label="配送时间：" prop="send_time_id">
              <el-select
                v-model.trim="form.send_time_id"
                placeholder="配送时间"
                class="wid220"
                clearable
                @change="getArticleList"
              >
                <el-option label="所有" value=""></el-option>
                <el-option
                  v-for="(send_time_list, index) in list.send_time_list"
                  :key="index"
                  :label="send_time_list"
                  :value="parseInt(index)"
                ></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="分拣状态：" prop="status">
              <el-select
                v-model.trim="form.status"
                placeholder="分拣状态"
                class="wid220"
                clearable
                @change="getArticleList"
              >
                <el-option label="所有" value=""></el-option>
                <el-option
                  v-for="(sort_status, index) in list.sort_status"
                  :key="index"
                  :label="sort_status"
                  :value="index + 1"
                ></el-option>
              </el-select>
            </el-form-item>
            <MainFormBtn @reset="reset" @getSearchFor="getSearchFor" :loading="listLoading" :showBtn="moredata">
            </MainFormBtn>
            <div class="more el-form-item" @click="more">
              <span>更多</span>
              <i :class="[{ on: moredata }, ' el-icon-arrow-down']"></i>
            </div>
            <div class="clearfix"></div>
            <el-collapse-transition>
              <div v-show="moredata">
                <div>
                  <el-form-item label="配送路线：" prop="line_id">
                    <el-select
                      v-model.trim="form.line_id"
                      placeholder="配送路线"
                      class="wid220"
                      clearable
                      @change="getArticleList"
                    >
                      <el-option label="所有" value=""></el-option>
                      <el-option
                        v-for="(sort_status, index) in line_info"
                        :key="index"
                        :label="sort_status"
                        :value="index"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item label="用户：" prop="uid">
                    <change-user-input
                      ref="changeUserInput"
                      @sendValue="getUser"
                      @clear="clearUid"
                    ></change-user-input>
                  </el-form-item>
                  <el-form-item label="订单：" prop="order_sn">
                    <el-input
                      v-model.trim="form.order_sn"
                      placeholder="订单"
                      clearable
                      class="wid220"
                    ></el-input>
                  </el-form-item>
                  <!-- 新增发货状态 待确认绑定值 -->
                  <el-form-item label="发货状态：" prop="order_status">
                    <el-select
                      v-model.trim="form.order_status"
                      placeholder="发货状态"
                      class="wid220"
                      clearable
                      @change="getArticleList"
                    >
                      <el-option label="所有" value=""></el-option>
                      <el-option label="已发货" value="2"></el-option>
                      <el-option label="未发货" value="1"></el-option>
                      <!-- <el-option
                      v-for="(item, index) in list.order_status"
                      :key="index"
                      :label="item"
                      :value="parseInt(index) + 1"
                    ></el-option> -->
                    </el-select>
                  </el-form-item>
                  <div class="clearfix"></div>
                  <el-form-item label=" ">
                    <MainFormBtn class="btn-bottom" @reset="reset" @getSearchFor="getSearchFor" :loading="listLoading" :showBtn="!moredata">
                    </MainFormBtn>
                  </el-form-item>
                </div>
              </div>
            </el-collapse-transition>
          </el-form>
        </div>
        <div class="main-controls-wrap">
          <div>
            <el-button class="mainor_tea fill-height" @click="revocation">批量撤回</el-button>
            <el-button class="mainor_tea fill-height" @click="pldeliver">批量发货</el-button>
          </div>
        </div>
        <div class="main_table">
          <el-table
          ref="multipleTable"
          v-loading="listLoading"
          :data="list.list.data"
          element-loading-text="加载中"
          fit
          border
          highlight-current-row
          @selection-change="handleSelectionChange"
          :header-cell-class-name="this.$verticaline"
          :height="borderHeight"
          :header-cell-style="tableHeightStyle"
          @header-dragend="changeTableWidth"
          @row-dblclick="rowDblclick"
        >
          <el-table-column type="selection" :selectable="selectInit" align="center" />
          <el-table-column
            label="订单号"
            prop="order_sn"
            :width="tableWidth[hash + 'order_sn'] || 180"
          />
          <el-table-column
            label="用户名称"
            prop="nickname"
            :width="tableWidth[hash + 'nickname']"
          >
            <template slot-scope="scope"
              >{{ scope.row.member ? scope.row.member.nickname : "" }}
              <span v-if="scope.row.zid_info"
                >【{{ scope.row.zid_info.nickname }}】</span
              ></template
            >
          </el-table-column>
          <el-table-column
            label="发货时间"
            prop="delivery_time"
            :width="tableWidth[hash + 'delivery_time']"
          >
            <template slot-scope="scope">{{
              scope.row.delivery_time
                ? dayjs(scope.row.delivery_time * 1000).format(
                    "YYYY-MM-DD HH:mm:ss"
                  )
                : ""
            }}</template>
          </el-table-column>
          <el-table-column
            label="分拣状态"
            prop="status"
            :width="tableWidth[hash + 'status']"
          >
            <template slot-scope="scope"
              ><span :class="'order' + scope.row.order_list_status">
                {{ list.sort_status[scope.row.order_list_status] }}
              </span></template
            >
          </el-table-column>
          <el-table-column
            label="发货状态"
            prop="order_status"
            :width="tableWidth[hash + 'order_status']"
          >
            <template slot-scope="scope"
              ><span
                :class="
                  scope.row.order_status == 2 || scope.row.order_status == 3
                    ? 'success'
                    : 'unpaid'
                "
              >
                {{
                  scope.row.order_status == 2 || scope.row.order_status == 3
                    ? "已发货"
                    : "未发货"
                }}</span
              ></template
            >
          </el-table-column>
          <el-table-column
            label="配送路线"
            prop="line_id"
            :width="tableWidth[hash + 'line_id']"
          >
            <template slot-scope="scope"
              ><span>
                {{ line_info[scope.row.line_id] }}
              </span></template
            >
          </el-table-column>
          <el-table-column
            label="管理操作"
            align="left"
            fixed="right"
            prop="operate"
            :width="tableWidth[hash + 'operate'] || 200"
            class-name="main_hei"
            label-class-name="main-center"
          >
            <template slot-scope="scope">
              <el-link
                type="danger"
                v-if="scope.row.order_status == 2"
                @click="returnOrder(scope.row)"
                >退回订单</el-link
              >
              <el-link
                type="success"
                @click="(id = scope.row.id), sendOrder_info(scope.row)"
                >查看</el-link
              >
              <el-link
                type="warning"
                @click="deliver(scope.$index, scope.row.id)"
                v-if="
                  scope.row.order_status == 1 &&
                  scope.row.order_list_status == 2
                "
                >发货</el-link
              >
              <!-- <el-link>打印</el-link> -->
            </template>
          </el-table-column>
          </el-table>
        </div>
        <div class="main_page boxdq">
          <div class="main_num">
            <div class="main_num_l flex-row-start">
              <p>
                订单数量：
                <em>{{ list.all }}</em>
              </p>
              <p>
                未发订单：
                <em>{{ list.all_un }}</em>
              </p>
              <p>
                已发订单：
                <em>{{ list.all_ed }}</em>
              </p>
              <div class="mainsu_te marginRight5">
                <el-tooltip class="item" effect="dark" placement="bottom">
                  <div slot="content">注释：已完成分拣，但未发货的订单</div>
                  <svg
                    aria-hidden="true"
                    class="navbar_svg"
                    width="16"
                    height="16"
                  >
                    <use xlink:href="#icon-summary_question" />
                  </svg>
                </el-tooltip>
              </div>
              <p>
                可发订单：
                <em>{{ list.all_ok }}</em>
              </p>
              <p class="box" style="width: 400px; align-items: center">
                发货进度：
                <el-progress
                  :text-inside="true"
                  :stroke-width="14"
                  :percentage="fenjian_percent"
                  status="success"
                  color="#E47C02"
                  style="width: 60%"
                ></el-progress>
              </p>
            </div>
          </div>

          <!-- 分页 -->
          <div class="main_page_r">
            <MainPagination
              :current-page="current.page"
              :page-sizes="[50, 100, 200]"
              :page-size="limit"
              layout="total, sizes, prev, pager, next, jumper"
              :total="totalCount"
              background
              @size-change="changeLimit"
              @current-change="changePage"
            />
          </div>
        </div>

        <!-- 批量发货 -->
        <el-dialog
          :title="'已选择' + selectArr.length + '个订单，发货出库中！'"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          @close="close"
          :visible.sync="addedFormVisible"
          class="main_dialog dialog450 deliveryDialog"
        >
          <el-progress
            :text-inside="true"
            :stroke-width="15"
            :percentage="percent"
            status="success"
            color="#E47C02"
            style="width: 100%"
          ></el-progress>
          <div class="progress_list">
            <template v-for="(percent_list, index) in reverseSum">
              <template v-if="index < 5">
                <p v-if="percent_list.type == 1" :key="index">
                  订单id:{{ `${percent_list.order_id}，${percent_list.msg}` }}
                </p>
                <p v-else class="progress_list_red" :key="index">
                  订单id:{{ `${percent_list.order_id}，${percent_list.msg}` }}
                </p>
              </template>
            </template>
            <p v-if="percent == 100" class="progress_list_su">
              发货已经完成请关闭弹框!
            </p>
          </div>
          <div slot="footer" class="flex-center" v-if="isInsufficient">
            <el-button class="mainor_tea fill-height" type="primary" @click="changeInventoryVisible">库存不足详情</el-button>
          </div>
        </el-dialog>
        
        <!-- 查看 -->
        <el-dialog
          title="查看"
          :visible.sync="seeFormVisible"
          class="main_dialog dialog1000"
        >
          <div class="main_xq">
            <ul class="boxha">
              <li>
                订单号：<span>{{ info.info.order_sn }}</span>
              </li>
              <li>
                用户名称：<span>{{ info.info.nickname }}</span
                ><span v-if="info.info.zid_info"
                  >【{{ info.info.zid_info.nickname }}】</span
                >
              </li>
              <li>
                收货人：<span>{{ info.info.contact }}</span>
              </li>
              <li>
                收货手机：<span>{{ info.info.mobile }}</span>
              </li>
              <li class="main_w100">
                收货地址：<span>{{ info.info.address }}</span>
              </li>
            </ul>
          </div>
          <div class="main_table marginTop20">
            <el-table
              ref="multipleTable1"
              v-loading="listLoading"
              :data="info.info.order_list"
              element-loading-text="加载中"
              fit
              highlight-current-row
            >
              <el-table-column label="序号">
                <template slot-scope="scope">{{ scope.$index + 1 }}</template>
              </el-table-column>
              <el-table-column
                label="商品名称"
                prop="userNickname"
                class-name="main_hei"
                width="180"
              >
                <template slot-scope="scope">
                  <span
                    v-if="scope.row.out_status == 1 ? true : false"
                    style="color: #e6a23c"
                  >
                    【缺】
                  </span>
                  <span
                    v-if="scope.row.modify == 1 ? true : false"
                    style="color: #e6a23c"
                  >
                    【更】 </span
                  >{{ scope.row.name }}【{{
                    scope.row.goods_spu.spu_name.title
                  }}】</template
                >
              </el-table-column>
              <el-table-column
                label="SKU编码"
                prop="goods_spu.goods_spu_code"
                class-name="main_hei"
              />
              <el-table-column
                label="下单量"
                prop="order_num"
                class-name="main_hei"
              >
                <template slot-scope="scope">
                  <span
                    :style="{
                      color: scope.row.out_status == 1 ? '#e6a23c' : '',
                    }"
                  >
                    {{ scope.row.order_num + scope.row.unit }}
                  </span></template
                >
              </el-table-column>
              <el-table-column
                label="分拣量"
                prop="sort_num"
                class-name="main_hei"
              >
                <template slot-scope="scope">
                  <span
                    :style="{
                      color: scope.row.out_status == 1 ? 'red' : '',
                    }"
                  >
                    <!-- {{scope.row.sort_num +(scope.row.transfer_unit? scope.row.transfer_unit: scope.row.unit)}} -->
                    {{ scope.row.sort_num + scope.row.unit }}
                  </span></template
                >
              </el-table-column>
              <el-table-column
                label="当前库存"
                prop="userNickname"
                class-name="main_hei"
              >
                <template slot-scope="scope"
                  ><span v-if="is_delivery">
                    {{
                      scope.row.base_order_num
                        ? scope.row.base_order_num
                        : (scope.row.goods_spu.inventory
                            ? scope.row.goods_spu.inventory.num
                            : "0.00") +
                          " " +
                          scope.row.unit
                    }}</span
                  >
                  <span v-else> / </span>
                </template>
              </el-table-column>
              <el-table-column label="分拣状态" prop="status">
                <template slot-scope="scope"
                  ><span :class="[scope.row.status == 1 ? 'sort1' : 'sort0']">
                    {{ info.status[scope.row.status] }}</span
                  ></template
                >
              </el-table-column>
            </el-table>
          </div>
          <div slot="footer" class="dialog-footer">
            <el-button
              type="primary"
              @click="seeupmine"
              v-repeatClick
              v-if="
                info.info.order_status == 1 && info.info.order_list_status == 2
              "
              >发 货</el-button
            >
          </div>
        </el-dialog>
        <!-- 批量撤回 -->
        <el-dialog
          title="批量撤回，请勿刷新/关闭页面，可能导致页面操作失败!"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          @close="close"
          :visible.sync="revocationVisible"
          class="main_dialog dialog1300"
        >
          <revocation
            :dataList="dataList"
            :sort_status="list.sort_status"
            @close="close"
          ></revocation>
        </el-dialog>
        <!-- 库存不足详情 -->
        <inventoryDialog :visible.sync="inventoryVisible" :taskId="taskId"></inventoryDialog>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
import {
  sendOrder_index,
  sendOrder_info,
  sendOrder_bd,
  sendOrder_batchDispatchGoods,
  return_order,
} from "@/api/warehouse/warehouseDelivery";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { parseTime } from "@/utils/index";
import dayjs from "dayjs";
import { mixins } from "@/mixins/index.js";
import revocation from './components/revocation/index.vue'
import inventoryDialog from './components/delivery/inventoryDialog.vue'
export default {
  mixins: [mixins],
  components: { revocation, inventoryDialog },
  computed: {
    ...mapGetters(["avatar"]),
    reverseSum() {
      return this.percent_list.reverse();
    },
    isInsufficient() {
      return this.percent_list.some(item => item.msg.includes("库存不足"));
    },
    dataList () {
      return this.list.list.data.filter(el => el.order_status === 2)
    },
    // 分拣经度进度
    fenjian_percent() {
      let percent = 0;
      let total = this.totalCount;
      let all_ed = this.all_ed;
      // this.list.list.data.map((e) => {
      //   if (e.order_status == 2 || e.order_status == 3) {
      //     percent += 1;
      //   }
      // });
      // if (total) {
      //   percent = parseFloat((percent / total) * 100).toFixed(2);
      // }
      percent = parseFloat((all_ed / total) * 100).toFixed(2);
      return parseFloat(percent);
    },
  },
  data() {
    return {
      // 时间
      parseTime,
      dayjs,
      // 分页
      current: {
        page: 1,
        per_page: 50,
      },
      limit: 50,
      totalCount: 1,
      // 更多
      moredata: false,
      // 列表数据
      list: {
        list: {
          data: [],
        },
      },
      line_info: {},
      info: {
        info: {
          order_sn: "",
          contact: "",
          mobile: "",
          address: "",
          company_name: {
            company_name: "",
          },
          order_list: [],
        },
        order_status: ["未分拣"],
        status: ["未分拣"],
      },
      id: "",
      seeFormVisible: false,
      listLoading: false,
      // 搜索
      form: {
        send_time: parseTime(new Date(), "{y}-{m}-{d}"),
        send_time_id: null,
        status: null,
        uid: "",
        order_sn: "",
        order_status: null,
        line_id: "",
      },
      all_ed: 0,
      // 是否发货
      is_delivery: true,
      // 批量发货
      percent_gs: 0,
      percent: 0,
      percent_list: [],
      addedFormVisible: false,
      // 全选
      selectArr: [],
      revocationList: [], //  批量撤回数据
      revocationData: [], //  批量撤回数据
      removeFormVisible: false,  
      revocationTypeData: [],
      revocationVisible: false,
      inventoryVisible: false, // 库存不足详情弹框状态
      taskId: null, // 批量发货消息通知id
    };
  },
  mounted() {
    this.setupEchoListeners(this.avatar.company_id);
  },
  created() {
    // 列表
    this.getNumerical(200);
    this.sendOrder_index();
  },
  methods: {
    //  表格双击跳转详情页面
    rowDblclick(row, column, event) {
      this.id = row.id
      this.sendOrder_info(row)
    },
    // 设置事件监听
    setupEchoListeners(company_id) {
      if(!window.Echo) return;
      window.Echo.channel(`batchSendGoods.${company_id}`).listen("BacthSendGoodsEvent",(e) => {
        let { rate, msg, order_id, task_id } = e.notice;
        if(task_id == this.taskId) {
          this.percent = parseInt((rate * 100));
          this.percent_list.push({
            num: this.percent,
            type: e.notice.code == 200 ? 1 : 2,
            order_id,
            msg,
          });
        }
      });
    },
    // 敲击键盘回车键时调用的搜索回调
    startGetting() {
      this.getSearchFor();
    },
    // 点击搜索时折叠搜索条件
    getSearchFor() {
      this.getArticleList();
    },
    //获取用户信息
    getUser(data) {
      let uid = data.info.user_id;
      this.form.uid = uid;
      this.sendOrder_index();
    },
    // 清除用户的uid
    clearUid() {
      this.form.uid = "";
    },
    // 关闭清空表单
    close() {
      this.percent = 0;
      this.revocationVisible = false;
      this.percent_gs = 0;
      this.percent_list = [];
      this.sendOrder_index();
    },
    beforeClose() {
      if (this.percent < 100) {
        this.$confirm("此操作将中断出库数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.addedFormVisible = false;
          })
          .catch(() => {
            window.open(`https://${window.location.host}/cadmin#/`);
          });
      } else {
        this.addedFormVisible = false;
      }
    },
    // 监听全选
    handleSelectionChange(val) {
      this.selectArr = [];
      val.map((item) => {
        this.selectArr.push({ id: item.id });
      });
    },
    // 监听绑定全选不可勾选
    selectInit(row, index) {
      if (row.order_status == 1 && row.order_list_status == 2) {
        return true;
      } else {
        return false;
      }
    },
    changeInventoryVisible() {
      this.inventoryVisible = !this.inventoryVisible;
    },
    // 查看发货
    sendOrder_info(row) {
      if (row.order_status == 2 || row.order_status == 3) {
        this.is_delivery = false;
      } else {
        this.is_delivery = true;
      }

      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      sendOrder_info(data).then((res) => {
        this.seeFormVisible = true;
        if (res.errcode == 0) {
          this.info = res.data;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    seeupmine() {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: this.id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: this.id }
      );
      this.$confirm("确定发货吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          sendOrder_bd(data).then((res) => {
            this.seeFormVisible = false;
            if (res.errcode == 0) {
              this.$message({
                message: "发货成功",
                type: "success",
              });
              this.sendOrder_index();
            } else {
              this.$message.error(res.errmsg);
            }
          });
        })
        .catch(() => {});
    },
    // 批量发货
    async setupmine() {
      let ids = this.selectArr.map((item) => item.id);
      let data = {
        ids: ids.join(","),
      };
      let query = this.packageApi(data);
      this.percent_list = [];
      this.percent = 0;
      sendOrder_batchDispatchGoods(query).then((res) => {
        if (res.errcode == 0) {
          this.addedFormVisible = true;
          this.taskId = res.data.task_Id;
        } else if (res.errcode == 61212) {
          this.$message.error(res.errmsg);
          setTimeout(() => {
            this.sendOrder_index();
          }, 1000);
        }
      });
      return;
      let that = this;
      that.addedFormVisible = true;
      let dataList = this.selectArr.map((item) => item.id);
      // 成功发货数量
      let successNum = 0;
      async function Fun() {
        let id = dataList.shift(); // 从队列中取出第一个数据进行处理
        let status = false;
        return new Promise((resolve, reject) => {
          let datas = {
            id,
          };
          let query = that.packageApi(datas);
          let timeoutId = setTimeout(() => {
            status = true;
            // 如果请求超时，直接进行下一个 Fun 方法调用
            dataList.length > 0 && Fun();
            reject(new Error("Request timeout"));
          }, 5000); // 设置超时时间为5秒
          sendOrder_bd(query).then((res) => {
            clearTimeout(timeoutId); // 清除超时计时器
            status = !status;
            successNum += 1;
            that.percent = Number(
              (Number(successNum / that.selectArr.length) * 100).toFixed(0)
            );
            if (dataList.length != 0 && status) {
              setTimeout(() => {
                Fun();
              }, 500);
            }
            if (res.errcode == 0) {
              resolve();
            } else {
              reject();
            }
          });
        });
      }
      await Fun();
    },
    pldeliver() {
      if (this.selectArr.length != 0) {
        this.setupmine();
      } else {
        this.$message.error("请勾选订单");
      }
    },
    // 发货
    deliver(index, id) {
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, { id: id })) +
              apiUrl().appsecret
          ),
        },
        apiUrl().name,
        { id: id }
      );
      this.$confirm("确定发货吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          sendOrder_bd(data).then((res) => {
            if (res.errcode == 0) {
              this.$message({
                message: "发货成功",
                type: "success",
              });
              this.sendOrder_index();
            } else if (res.errcode == 61212) {
              this.$message.error(res.errmsg);
              setTimeout(() => {
                this.sendOrder_index();
              }, 1000);
            } else {
              this.$message.error(res.errmsg);
            }
          });
        })
        .catch(() => {});
    },
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.sendOrder_index();
    },
    // 点击搜索时将多余的搜索条件隐藏
    getSearchFor() {
      this.getArticleList();
      this.moredata = false;
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.$refs["changeUserInput"].name = "";
      this.sendOrder_index();
    },
    // 更多
    more() {
      this.moredata = !this.moredata;
    },
    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.sendOrder_index();
    },
    changePage(page) {
      this.current.page = page;
      this.sendOrder_index();
    },
    // 列表
    sendOrder_index() {
      this.listLoading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(
              Object.assign(apiUrl().name, this.list_form(), this.current)
            ) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      sendOrder_index(data).then((res) => {
        this.listLoading = false;
        if (res.errcode == 0) {
          this.list = res.data;
          this.all_ed = res.data.all_ed;
          this.totalCount = res.data.list.total;
          this.line_info = res.data.line_info;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));

      return form;
    },
    returnOrder(row) {
      let data = {
        id: row.id,
      };
      let query = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, data)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        data
      );
      this.$confirm("此操作将回退订单, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          return_order(query).then((res) => {
            if (res.errcode == 0) {
              this.$message({
                type: "success",
                message: "退回成功!",
              });
              this.sendOrder_index();
            } else {
              this.$message({
                type: "error",
                message: res.errmsg,
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消退回",
          });
        });
    },
    // 封装请求的sign和timeStamp字段
    packageApi(data = {}) {
      let query = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        data
      );
      return query;
    },
    //  批量撤回
    revocation () {
      this.revocationVisible = true
      return 
      if (this.selectArr.length != 0) {
        this.percent_list = [];
        this.revocationTypeData = []
        this.percent = 0;
        this.$confirm("此操作将批量回退订单, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }).then(async res => {
          let ids = this.selectArr.map((item) => item.id);
          this.revocationList = ids
          this.revocationData = []
          this.removeFormVisible = true
          for (const id of ids) {
            await this.revocationById(id)
          }
          this.getNumerical()
        })
      } else {
        this.$message.error("请勾选订单");
      }
    },
    async revocationById(id) {
      let data = {
        id
      };
      let query = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name, data)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        data
      );
      await return_order(query).then((res) => {
        this.revocationData.push(id)
        if (res.errcode == 0) {
          this.revocationTypeData.push({
            num: 100,
            type: 1,
            order_id: id,
            msg: res.errmsg,
          })
        } else if (res.errcode == 40009) {
          this.revocationTypeData.push({
            num: 100,
            type: 2,
            order_id: id,
            msg: res.errmsg,
          })
        }
      });
    }
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.mainsu {
  .mainor_form form {
    width: 100%;
  }
  .main_num {
    .mainsu_te {
      position: relative;
      top: -1px;
    }
  }
}
/deep/.el-progress-bar__innerText {
  transform: translateY(-1px);
}
.main_dialog {
  .main_table {
    /deep/.el-table__body-wrapper {
      overflow-y: auto;
      height: 400px;
    }
  }
  .main_xq ul li {
    width: 33.33%;
    margin-top: 5px;
    margin-bottom: 5px;
  }
  .progress_list {
    margin-top: 10px;
    .progress_list_wrap {
      max-height: 300px;
      overflow-y: auto;
      margin-bottom: 10px;
    }
    p {
      height: 24px;
      line-height: 24px;
    }
    .progress_list_red {
      color: red;
    }
    .progress_list_su {
      color: #03a98e;
    }
  }
}

// 支付状态
.success {
  color: $order_color3;
}
.unpaid {
  color: $colour_red;
}
// 订单状态
.order1 {
  color: $order_color1;
}
.order2 {
  color: $order_color2;
}
.order3 {
  color: $order_color3;
}
.order4 {
  color: $order_color4;
}

// 分拣状态
.sort1 {
  color: #03a98e;
}
.sort0 {
  color: red;
}

/deep/.mainor_form form .el-form-item {
  margin-bottom: 10px;
  &:last-child {
    margin-bottom: 4px;
  }
}
/deep/.el-link {
  margin-left: 0;
}
.main_page {
  margin-left: 0;
}
.deliveryDialog {
  /deep/.el-dialog__body {
    padding-bottom: 20px;
  }
  /deep/.el-dialog__footer {
    padding-top: 0;
    border-top: none;
  }
}
</style>
